<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<div class="am-modal" tabindex="-1" id="downloadTemplatemodal">
	<div class="am-modal-dialog">
		<div class="am-modal-hd">
			下载模版 <a href="javascript: void(0)" class="am-close"
				data-am-modal-close>&times;</a>
		</div>
		<div class="am-modal-bd">
			<form action="<%=request.getContextPath() %>/downloadTemplate"
				target="_blank" method="post" class="am-form"
				id="downloadTemplateForm">
				<div class="am-g am-margin-top">
					<div class="am-u-sm-4 am-u-md-2 am-text-right">学科</div>
					<div class="am-u-sm-8 am-u-md-10">
						<select data-am-selected="{btnSize: 'sm',maxHeight:200}"
							name="majorCode" multiple>
							<option value="">请选择学科</option>
							<c:forEach items="${majorList }" var="major">
								<option
									<c:if test="${major.majorCode eq majorCode}"> selected="selected"</c:if>
									value="${major.majorCode }">${major.majorName }</option>
							</c:forEach>
						</select>
					</div>
				</div>
			</form>
		</div>
		<div class="am-modal-footer">
			<span class="am-modal-btn" data-am-modal-confirm>下&nbsp;&nbsp;载</span>
			<span class="am-modal-btn" data-am-modal-cancel>取&nbsp;&nbsp;消</span>
		</div>
	</div>
</div>

<script>
	function downloadTemplate(){
		$('#downloadTemplatemodal').modal({
			relatedTarget: this,
			closeOnConfirm: false,
			onConfirm: function(e) {
				var mcLength = $("#downloadTemplateForm select[name='majorCode']>option:checked").length;
				if(mcLength > 0){
					$("#downloadTemplateForm")[0].submit();
					clearDownloadTemplate();
					// this.$element.modal("close");
				}
				else{
					layer.msg("请选择学科", {time: 1500});
				}
			},
			onCancel: function(e) {
				clearDownloadTemplate();
			}
		});
	}
	
	function clearDownloadTemplate(){
		var $option = $($('#downloadTemplateForm')[0].majorCode).find('option');
		$option.prop('selected',false);
		$option.eq(0).prop('selected', true);
		$option.eq(0).trigger('changed.selected.amui');
	}
</script>